/* 
 * Copyright 2014 Josef Hertl.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package caetus.modelChecking.variable;

/**
 * Represents a simple base variable.
 *
 * @author Josef Hertl
 */
public class ModelBaseVariable extends ModelVariable {

    /**
     * The name the variable has as a constant
     */
    private String nameConstant;
    private ModelVariableType type;

    public ModelBaseVariable(String name, ModelVariableType type) {
        this.name = name;
        this.type = type;
        this.nameConstant = name.toLowerCase();
    }

    @Override
    public String getVariableType() {
        return type.getHlpsl();
    }

    @Override
    public int compareTo(ModelVariable o) {
        if (o instanceof ModelBaseVariable) {
            if (getVariableType().equals(o.getVariableType())) {
                return getVariableName().compareTo(o.getVariableName());
            } else {
                return type.compareTo(((ModelBaseVariable) o).type);
            }
        } else {
            return -1;
        }
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 89 * hash + (this.nameConstant != null ? this.nameConstant.hashCode() : 0);
        hash = 89 * hash + (this.type != null ? this.type.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ModelBaseVariable other = (ModelBaseVariable) obj;
        if ((this.nameConstant == null) ? (other.nameConstant != null) : !this.nameConstant.equals(other.nameConstant)) {
            return false;
        }
        if (this.type != other.type) {
            return false;
        }
        return true;
    }
}
